#pragma once

#include "ExpansionNode.h"

#include "ExpansionRegion.h"

namespace uml {

ExpansionNode::ExpansionNode(const QString& umlType)
    : ObjectNode(umlType) {}

void ExpansionNode::fromJson(const QJsonObject& json, QStringList& errorList) {
    if (json.isEmpty()) {
        return;
    }

    ObjectNode::fromJson(json, errorList);
    regionAsInput_ = JsonSerializable::create<ExpansionRegion>(json.value("regionAsInput"), errorList);

    regionAsOutput_ = JsonSerializable::create<ExpansionRegion>(json.value("regionAsOutput"), errorList);

}

void ExpansionNode::toJson(QJsonObject& json) {
    ObjectNode::toJson(json);
    if (regionAsInput_) {
        QJsonObject regionAsInput_json;
        regionAsInput_->toJson(regionAsInput_json);
        json.insert("regionAsInput", regionAsInput_json);
    }
    if (regionAsOutput_) {
        QJsonObject regionAsOutput_json;
        regionAsOutput_->toJson(regionAsOutput_json);
        json.insert("regionAsOutput", regionAsOutput_json);
    }
}

/// <summary>
/// regionAsInput getter
/// The ExpansionRegion for which the ExpansionNode is an input.
/// </summary>
shared_ptr<ExpansionRegion> ExpansionNode::regionAsInput() const {
    return regionAsInput_;
}

/// <summary>
/// regionAsInput setter
/// The ExpansionRegion for which the ExpansionNode is an input.
/// </summary>
void ExpansionNode::setRegionAsInput(shared_ptr<ExpansionRegion> value) {
    regionAsInput_ = value;
}

/// <summary>
/// regionAsOutput getter
/// The ExpansionRegion for which the ExpansionNode is an output.
/// </summary>
shared_ptr<ExpansionRegion> ExpansionNode::regionAsOutput() const {
    return regionAsOutput_;
}

/// <summary>
/// regionAsOutput setter
/// The ExpansionRegion for which the ExpansionNode is an output.
/// </summary>
void ExpansionNode::setRegionAsOutput(shared_ptr<ExpansionRegion> value) {
    regionAsOutput_ = value;
}

} // namespace uml
